﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Teamplate.Master" AutoEventWireup="true" CodeBehind="GianHangSach.aspx.cs" Inherits="WebNhaXuatBan.GianHangSach" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <a style="margin-left:30px;" href="default.aspx"><img src="Images/Folder-Home-Folder-icon.png" alt="Group EM09" /></a>
    <a style="margin-left:30px;"  href="DauThauSach.aspx"><img src="Images/auction-guy.png" alt="Group EM09" /></a>
    <a style="margin-left:30px;"  href="GianHangSach.aspx"><img src="Images/HoverBookes.png" alt="Group EM09" /></a>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div style="width:980px; margin-left:auto; margin-right:auto; border:1px solid #bad9eb;">
<div style="width:980px;height:30px; background-image:url(../Images/ThanhTieuDe.png);"></div>
<div style="height:20px;margin-top:5px;margin-left:5px;margin-bottom:10px;">
    <asp:Label ID="Label1" runat="server" Text="Hiển Thị Theo Loại Sách:" 
        ForeColor="Red"></asp:Label>
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        DataSourceID="SqlDataSource1" DataTextField="TenLoaiSach" 
        DataValueField="MaLoaiSach">
    </asp:DropDownList>
 </div>       
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NhaXuatBanConnectionString %>" 
        SelectCommand="SELECT [MaLoaiSach], [TenLoaiSach] FROM [LoaiSach]">
    </asp:SqlDataSource>
<div id="BODY">
<%
   BUS.SachBUS sach=new BUS.SachBUS();
   ArrayList dssach= sach.LayDanhSachSachTheoMaLoaiSach(DropDownList1.SelectedValue.ToString());
   int soBatDau = 0;
   int count = dssach.Count;
   int sotrang = 0;
   if (dssach.Count > 5)
   {
       count = 5;
       sotrang = dssach.Count / 5;
       if (dssach.Count % 5 > 0)
       {
           if (soBatDau == dssach.Count / 5)
           {
               count = dssach.Count % 5;
           }
           sotrang++;
       }
   }
   if (sotrang != 0 && sotrang != 1)
   { 
    %>
     <a style=" margin-left:2px; color:#4ba2d5" href="#TrangDau" onclick="LayDanhSach(<%=0 %>,<%=DropDownList1.SelectedValue %>,'<%=DropDownList1.SelectedItem.Text %>')">Trang Đầu</a>
     <%int sob = soBatDau / 10;
                sob = sob * 10;
                int soc = sob + 10;
                if (soc > sotrang)
                {
                    soc = sotrang;
                }
                if (sob != 0)
                {
        %>
        <a style=" margin-left:2px; color:#4ba2d5;" href="#TrangDau" onclick="LayDanhSach(<%=(sob - 1)%>,<%=DropDownList1.SelectedValue %>,'<%=DropDownList1.SelectedItem.Text %>')"><< Trước</a>
        <%}
            for (int i = sob; i < soc; i++)
            {
                if (i == soBatDau)
                {
                    %><span><%=i %></span>
                    <%
                }
                else
                {%>
                    <a style=" margin-left:2px; color:#4ba2d5;" href="#TrangDau" onclick="LayDanhSach(<%=i %>,<%=DropDownList1.SelectedValue %>,'<%=DropDownList1.SelectedItem.Text %>')"><%=i %></a>
                        <%
                }
            }
            if (soc < sotrang)
            {
                %>
                <a style=" margin-left:2px; color:#4ba2d5;" href="#TrangDau" onclick="LayDanhSach(<%=soc %>,<%=DropDownList1.SelectedValue %>,'<%=DropDownList1.SelectedItem.Text %>')"><%=soc %></a><%
            }
            if (sotrang != 0 && sotrang != 1)
            {
                %>
                <a style=" margin-left:2px; color:#4ba2d5;" href="#TrangDau" onclick="LayDanhSach(<%=sotrang-1 %>,<%=DropDownList1.SelectedValue %>,'<%=DropDownList1.SelectedItem.Text %>')">Trang Cuối</a><%
            }
                     %>
        <%} %>
        <br /><span style="margin-left:2px; margin-top:5px;">Hiển Thị:<%=" "+count %>/<%=dssach.Count+" kết quả" %></span>
    <%
   for (int j = soBatDau*5; j < soBatDau*5+count; j++)
   {%>
   <br />
   <hr />
   <div style="height:300px;margin-top:5px;margin-left:5px;width:100%;">
   <div style="height:300px;float:left;width:300px;">
   <a href="#"><img src="<%=((DTO.SachDTO)dssach[j]).FileHinh %>" alt="<%=((DTO.SachDTO)dssach[j]).FileHinh %>") /></a>
   </div>
   <div style="height:300px;float:left;width:600px;">
   <span style="color:#366276; font-size:30px;"><%= ((DTO.SachDTO)dssach[j]).TenSach%></span>
   <br />
   Tác Giả:<%=" "+((DTO.SachDTO)dssach[j]).TacGia%>
   <br />
   <span style="color:red;">Giá Bán:<%= " " + ((DTO.SachDTO)dssach[j]).GiaBan%>$</span>
   <br />
   Thể Loại:<%= " " + DropDownList1.SelectedItem.Text%>
   <br />
   <span style="color:red;"><%if (((DTO.SachDTO)dssach[j]).SoLuongTon != 0)
                              { %> Còn Hàng <%}
                              else
                              {%>Hết Hàng<%} %></span>
   <br />
   <%if (Session["TaiKhoan"] != null)
     { %><a href="DatMua.aspx?MaSach=<%=((DTO.SachDTO)dssach[j]).MaSach %>"><%}
     else
     { %><a href="DangKy.aspx"><%} %><img src="Images/buttonmuahang1.jpg" /></a>
   </div>
   </div>
   <%} %>
   <div style="width:980px;height:10px;"></div>
</div>
</div>
<script type="text/javascript">
    var $j = jQuery.noConflict();
    function LayDanhSach(ma, so,text) {
        $j.ajax({
            type: "POST",
            url: "GianHangSach.aspx/LayDanhSachSach",
            data: "{'sobatdau':" + ma + ",'maLoai':" + so +",'text':'"+text+"'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (message) {
                $j("#BODY").html(message.d);
            }
        });
    }
 </script>
</asp:Content>
